<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>Data-Table 表格</title>
    <link rel="stylesheet" href="__STATIC__/frame/layui/css/layui.css">
    <!--<link rel="stylesheet" href="http://cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css">-->
    <link rel="stylesheet" href="__STATIC__/frame/static/css/style.css">
    <link rel="icon" href="__STATIC__/frame/static/image/code.png">
</head>
<body class="body">
<div id="xiazai" style="display: none"></div>
<!-- 工具集 -->
<div class="my-btn-box">
    <span class="fl">
        <a class="layui-btn layui-btn-danger radius btn-delect" id="btn-delete-all">批量删除</a>
        <a class="layui-btn btn-add btn-default" id="btn-refresh"><i class="layui-icon">&#x1002;</i></a>
        <a class="layui-btn btn-add btn-default" onclick="daochu()">导出现有条件的excel表格</a>导出后请手动刷新
    </span>
    <span class="fr">
        <span class="layui-form-label">搜索条件：</span>
<form action="{:url('index/forward')}" method="post">
        <div class="layui-inline" id="fuzhi">
            <select class="layui-select" name="type"  style="width: 100px">
                {if $type==1}
                <option value="1" selected>提现</option>
                <option value="2">充值</option>
                {else}
                <option value="1">提现</option>
                <option value="2" selected>充值</option>
                {/if}
            </select>
            <select class="layui-select" name="status" style="width: 100px">
                {if $status==1}
                <option value="0">未处理</option>
                <option value="1" selected>已处理</option>
                {else}
                <option value="0" selected>未处理</option>
                <option value="1">已处理</option>
                {/if}
            </select>
            <input type="text" class="layui-select"{if $start_time} value="{$start_time}"{/if} name="start_time" placeholder="请输入查询开始时间" id="start_time">
            <input type="text" class="layui-select"{if $end_time} value="{$end_time}"{/if} name="end_time" placeholder="请输入查询结束时间" id="end_time">
            <input type="text" class="layui-select" {if $tiaojian} value="{$tiaojian}"{/if} name="tiaojian" placeholder="请输入用户名或姓名或昵称">
        </div>
        <button class="layui-btn mgl-20" name="tijiao">查询</button>
        </form>
    </span>
</div>

<!-- 表格 -->
<div class="layui-row">
<table class="layui-table" style="width: 100%">
    <thead>
    <tr style="width: 50%">
        <th style="width: 1%;text-align: center"><input type="checkbox" id="quanxuan"></th>
        <th style="text-align: center">订单号</th>
        <th style="text-align: center">用户名</th>
        <th style="text-align: center">open_id</th>
        <th style="text-align: center">微信号</th>
        <th style="text-align: center">手机号码</th>
        <th style="text-align: center">订单类型</th>
        <th style="text-align: center">订单金额</th>
        <th style="text-align: center">创建时间</th>
        <th style="text-align: center">最晚到账时间</th>
        <th style="text-align: center">状态</th>
        <th style="text-align: center">操作</th>
    </tr>
    </thead>
    <tbody id="tbody">
    {foreach $data as $value}
    <tr>
        <td style="text-align: center"><input type="checkbox" value="{$value['id']}"></td>
        <td style="text-align: center">{$value['order_number']}</td>
        <td style="text-align: center">{$value['user']}</td>
        <td style="text-align: center">{$value['open_id']}</td>
        <td style="text-align: center">{$value['weixin']}</td>
        <td style="text-align: center">
            {$value['phone']}
        </td>
        <td style="text-align: center">
            {if $value['type']==1}
                提现
            {else}
                充值
            {/if}
        </td>
        <td style="text-align: center">{$value['number']}</td>
        <td style="text-align: center">{$value['create_time']|date='Y-m-d H:i:s'}</td>
        <td style="text-align: center">{$value['end_time']|date='Y-m-d H:i:s'}</td>
        {if $value['status']==1}
        <td style="text-align: center">
            已处理
        </td>
        {else}
        <td style="text-align: center">
            未处理
        </td>
        {/if}
        <td  style="text-align: center"><a href="javascript:;" title="处理" onclick="edit({$value['id']})"><i class="layui-icon">&#xe642;</i></a><a href="javascript:;" title="删除" style="margin-left: 10px" onclick="del({$value['id']})"><i class="layui-icon">&#xe640;</i></a></td>
    </tr>
    {/foreach}
    </tbody>
</table>
</div>
<div style="text-align: center">
    <div id="test"></div>
</div>
<script type="text/javascript" src="__STATIC__/frame/layui/layui.all.js"></script>
<script type="text/javascript" src="__STATIC__/js/index.js"></script>
<script type="text/javascript" src="__STATIC__/js/jquery.3.3.1.min.js"></script>
<script type="text/javascript" src="__STATIC__/js/maowenke.js"></script>
<!-- 表格操作按钮集 -->
<script>
function daochu() {
    var $tiaojian = $("[name=tiaojian]").val();
    var $start_time = $("#start_time").val();
    var $end_time = $("#end_time").val();
    var $type     = $("[name=type]").val();
    var $status   = $("[name=status]").val();
    var $url      = "{:url('index/daochu')}";
    var $html     = $("<form action='"+$url+"'>" +
        "<input type='text' name='tiaojian' value='"+$tiaojian+"'>" +
        "<input type='text' name='start_time' value='"+$start_time+"'>" +
        "<input type='text' name='end_time' value='"+$end_time+"'>" +
        "<input type='text' name='type' value='"+$type+"'>" +
        "<input type='text' name='status' value='"+$status+"'><button id='zhens'>tijiao</button></form>");
    $("#xiazai").empty();
    $("#xiazai").append($html);
    $("#zhens").click();
//    $("[name=tijiao]").click();
}
    layui.use('laydate',function () {
        var laydate = layui.laydate;
        laydate.render({
            elem: '#start_time' //指定元素
            ,done:function (value, date, endDate) {
                getuser();
            }
        });
        laydate.render({
            elem: '#end_time' //指定元素
            ,done:function (value, date, endDate) {
                getuser();
            }
        });
    });
    $("[name=type]").change(function () {
        getuser();
    });
    $("[name=status]").change(function () {
        getuser();
    });
    layui.use('laypage',function () {
        var laypage = layui.laypage;

        //执行一个laypage实例
        laypage.render({
            elem: 'test' //注意，这里的 test1 是 ID，不用加 # 号
            ,count: parseInt("{$datarow}")//数据总数，从服务端得到
            ,layout:['limit','prev','page','next']
            ,limits:[10,20,30,40,50,60,70,80,90]
            ,jump:function (obj,first) {
                if(!first){
                    getuser();
                }
            }
        });
    });
    $("#quanxuan").change(function () {
        checkIsTrue($(this));
    });
    function getuser() {
        var $lay = getLaypage();
        var $tiaojian = $("[name=tiaojian]").val();
        var $start_time = $("#start_time").val();
        var $end_time = $("#end_time").val();
        var $type     = $("[name=type]").val();
        var $status   = $("[name=status]").val();
        $.post("{:url('page/forward')}",{tiaojian:$tiaojian,limit:$lay.limit,page:$lay.page,start_time:$start_time,end_time:$end_time,type:$type,status:$status},function (data) {
            console.log(data);
            $("#tbody").empty();
            if(data.code){
                var $str = '';
                $.each(data.data,function (i,v) {
                    var type = '';
                    if(v.type==1){
                        type = '提现';
                    }else{
                        type = '充值';
                    }
                    $str +='<tr>'+
                    '<td style="text-align: center"><input type="checkbox" value="'+v.id+'"></td>'+
                    ' <td style="text-align: center">'+toStr(v.order_number)+'</td>'+
                    ' <td style="text-align: center">'+toStr(v.user)+'</td>'+
                    '<td style="text-align: center">'+toStr(v.open_id)+'</td>'+
                        '<td style="text-align: center">'+toStr(v.weixin)+'</td>'+
                    '<td style="text-align: center">'+toStr(v.phone)+'</td>'+
                    '<td style="text-align: center">'+type+'</td>'+
                    '<td style="text-align: center">'+v.number+'</td>'+
                    '<td style="text-align: center">'+timeToStr(v.create_time,true)+'</td>'+
                    '<td style="text-align: center">'+timeToStr(v.end_time,true)+'</td>';
//                    '<td style="text-align: center">'+timeToStr(v.create_time,true)+'</td>';
                    if(v.status==1){
                        $str +='<td style="text-align: center">已处理</td>'
                    }else{
                        $str +='<td style="text-align: center">未处理</td>'
                    }
                   $str +='<td  style="text-align: center"><a href="javascript:;" title="处理" onclick="edit('+v.id+')"><i class="layui-icon">&#xe642;</i></a><a href="javascript:;" title="删除" style="margin-left: 10px" onclick="del('+v.id+')"><i class="layui-icon">&#xe640;</i></a></td>'+
                    '</tr>';
                });
                $("#tbody").append($str);
            }else {
                layer.msg(data.msg);
            }
        })
    }
    $("#btn-add").click(function () {
        var $html = $(this).attr('data-href');
        layer.open({ type: 2,
            title:'添加题目分类',
            skin: 'layui-layer-rim', //加上边框
            area: ['300px', '200px'], //宽高
            content: $html,
            end:function () {
                window.location.reload();
            }
        });
    });
    $("#btn-refresh").click(function () {
        window.location.reload();
    });
    function del($id) {
        layer.confirm('你确定要删除吗？',{btn:['确定','取消']},function () {
            $.post("{:url('del/forward')}",{id:$id},function (data) {
                console.log(data);
                if(data.code==200){
                    layer.msg(data.msg);
                    setTimeout(function () {
                        window.location.reload();
                    },500)
                }else{
                    layer.msg(data.msg);
                }
            })
        });

    };
    function edit($id) {
        layer.confirm('你确定已经处理了吗？',{btn:['确定','取消']},function () {
            $.post("{:url('api/forward')}",{id:$id},function (data) {
                console.log(data);
                if(data.code==200){
                    layer.msg(data.msg);
                    setTimeout(function () {
                       getuser();
                    },500)
                }else{
                    layer.msg(data.msg);
                }
            })
        });
    }
    $("#btn-delete-all").click(function () {
        var $id = getCheckbox($("[type=checkbox]"));
        layer.confirm('你确定要删除吗？',{btn:['确定','取消']},function () {
            $.post("{:url('del/forward')}",{id:$id},function (data) {
//                console.log(data);
                if(data.code==200){
                    layer.msg(data.msg);
                    setTimeout(function () {
                        window.location.reload();
                    },500)
                }else{
                    layer.msg(data.msg);
                }
            })
        });
    })
</script>
</body>
</html>